{include file="my/frameHeader"}
<div>
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格数据查询块 -->
            <!-- <div class="table-query">
                <form class="layui-form layui-inline J-search-form" action="">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索ID：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="id" autocomplete="off" placeholder="请输入id">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">老师姓名:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="teachername" autocomplete="off"
                                placeholder="请输入课老师姓名">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="name" autocomplete="off"
                                placeholder="请输入考试任务">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">老师角色:</label>
                        <div class="layui-input-block">
                            <select name="role" id="role">
                                <option value="">请选择</option>
                                <option value="0">监考</option>
                                <option value="1">巡考</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布时间:</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input J-query-params J-date" name="create_time"
                                placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                </form>
                <button class="layui-btn J-search" data-type="reload">搜索</button>
                <button class="layui-btn J-reload">重置</button>
            </div> -->

            <!-- 表格 -->
            <div>
                <form class="layui-form layui-fluid J-add-form" lay-filter="formTest">
                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务:</label>
                        <div class="layui-input-block">
                            <select name="taskid" id="role">
                                {volist name='taskdata' id='taskdata'}
                                <option value="{$taskdata.id}">{$taskdata.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="985" placeholder="请输入内容">
                    <input type="hidden" class="form-control" id="uid" name="uid" value="1" placeholder="请输入内容">
                </form>
                <table class="layui-hide" id="testTable" lay-filter="test"></table>
                <!-- 表格工具 -->
                <!-- <script type="text/html" id="toolbarDemo">
                 <div class="layui-btn-container">
                     <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                     <button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
                 </div>
             </script> -->

            </div>

            <!-- submit -->
            <div>

                <button class="layui-btn submit-btn J-add">添加</button>
            </div>

        </div>
    </div>
    <!-- <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">添加监考老师</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">查看监考申请</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">最终监考名单</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script> -->
    <script>

        $(function () {
            initClass("teacherlist");
            initTable();
            layuiDate(".J-date");
            $("#taskid").val(getUrlVariable('taskid'));



            // 删除
            $(".J-remove").click(function () {
                var data = {
                    id: $(this).attr("data-id"),
                };
                layerConfirm("{:url('test/teachermove')}", data);
            });
        });

        function initTable() {
            var table;
            // 请求路径
            var requireUrl = {
                add: "{:url('test/courseadd')}",
                edit: "{:url('test/teacheredit')}",
                remove: "{:url('test/teacherremove')}",
                list: "{:url('test/getCourseInfo')}",
            };

            layui.use("table", function () {
                table = layui.table;
                table.render({
                    elem: "#testTable",
                    url: requireUrl.list,
                    toolbar: "#toolbarDemo",
                    title: "老师列表",
                    totalRow: false,
                    height: "full-100",
                    cols: [
                        [
                            { type: "checkbox", fixed: "left" },
                            { field: "id", title: "序号" },
                            { field: "coursename", title: "课程名字" },
                            { field: "c_time", title: "课时", },
                            // , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 500 }
                        ],
                    ],
                    id: "testReload",
                    page: true,
                    parseData: function (res) {
                        return {
                            code: 0,
                            msg: "",
                            count: res.total,
                            data: res.record
                        };
                    },
                });


                // 新增
                $(".J-add").click(function () {
                var checkStatus = table.checkStatus('testReload');
                    var userInfo = $(".J-add-form").serialize();

                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg('请至少选择一条记录！', { icon: 7 });
                        return;
                    }

                    var delList = [];
                    for (var i = 0; i < data.length; i++) {
                        delList.push(data[i].id);
                    }

                    var ids = JSON.stringify(delList);
                    userInfo += '&ids=' + ids;

                    ajaxRequest('post', requireUrl.add, userInfo, function (data) {
                        var errMesage = data.msg ? data.msg : data;
                        data.code == 1 ? successTrip(data) : errorAlert(false, errMesage);
                        parent.location.reload();
                    });
                    return false;
                });

                //工具栏事件
                table.on("toolbar(test)", function (obj) {
                    switch (obj.event) {
                        case "add":
                            tableAdd({
                                addUrl: requireUrl.add,
                                layerTemp: $(".J-temple"),
                                title: "添加参考老师",
                            });
                            break;
                        case "batchdel":
                            tableBatchDel(checkStatus, requireUrl.remove);
                            break;
                    }
                });

                //监听行工具事件
                table.on("tool(test)", function (obj) {
                    var data = obj.data;

                    if (obj.event === "del") {
                        layerConfirm(requireUrl.remove, {
                            id: data.id,
                        });
                    } else if (obj.event === "edit") {
                        layerOpenInit(
                            "参考老师编辑",
                            $(".J-temple"),
                            function (index) {
                                var data = $("form").serialize();
                                ajaxRequest("post", requireUrl.edit, data, function (data) {
                                    data.code == 1
                                        ? successTrip(data)
                                        : errorAlert(false, data.msg);
                                });
                            },
                            function () {
                                ajaxRequest(
                                    "get",
                                    requireUrl.edit,
                                    {
                                        id: data.id,
                                    },
                                    function (res) {
                                        form.val("formTest", {
                                            //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                                            id: res.data.id, // "name": "value"
                                            kechengid: res.data.kechengid,
                                            taskid: res.data.taskid,
                                            demo: res.data.demo,
                                        });
                                    }
                                );
                            }
                        );
                    }
                });
            });

            // 搜索重置操作
            var active = {
                reload: function () {
                    var queryParams = serializeObject($(".J-search-form"));
                    console.log(queryParams);
                    //执行重载
                    table.reload(
                        "testReload",
                        {
                            page: {
                                curr: 1, //重新从第 1 页开始
                            },
                            where: queryParams,
                        },
                        "data"
                    );
                },
            };
            $(".J-search").on("click", function () {
                var type = $(this).data("type");
                active[type] ? active[type].call(this) : "";
            });
            $(".J-reload").on("click", function () {
                $(".J-query-params").val("");
                form.render("select");
                active.reload ? active.reload.call(this) : "";
            });
        }
    </script>

    {include file="my/footer"}
</div>